package com.example.tsproject.Controller;

import com.example.tsproject.entity.Posts;
import com.example.tsproject.mapper.PostsMapper;
import org.springframework.ai.chat.client.ChatClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import reactor.core.publisher.Flux;

import java.util.List;

/**
 * @BelongsProject: t-s-project
 * @BelongsPackage: com.example.tsproject.Controller
 * @Author: YoungDra
 * @CreateTime: 2024/09/25  19:57
 */
@RestController
@RequestMapping("/ai")
@CrossOrigin
public class AIController {
    @Autowired
    PostsMapper postsMapper;
    private final ChatClient chatClient;

    AIController(ChatClient chatClient) {
        this.chatClient = chatClient;
    }

    @RequestMapping ("/chat")
    public String chat(@RequestParam String message) {
        System.out.println(message);
        return chatClient.prompt().user(message).call().content();

    }
    @RequestMapping(value = "/chat/stream",produces="text/html;charset=UTF-8")
    public Flux<String> chatStream(@RequestParam(value = "msg") String message) {
        return chatClient.prompt().user(message).stream().content();
    }
    @GetMapping("/ss")
    List<Posts> vv(){
        return postsMapper.selectList(null);
    }
}
